package org.proddevplm.dao.core;

import org.hibernate.Query;
import org.hibernate.Session;
import org.proddevplm.dao.api.IDiaMgmt;
import org.proddevplm.dao.data.dia.Diagram;
import org.proddevplm.dao.util.HibernateUtil;

public class DiaMgmt implements IDiaMgmt{

	@Override
	public boolean saveDia(Diagram dia) {
		
		HibernateUtil.currentSession().persist(dia);
		
		return false;
	}

	@Override
	public Diagram loadDia(int productId) {
		
		Session session = HibernateUtil.currentSession();
		Query q = session.createQuery("select d from Diagram d where d.productId=:productId");
		q.setInteger("productId", productId);
		return (Diagram)q.uniqueResult();
	}

	@Override
	public boolean updateDia(Diagram dia) {
		
		HibernateUtil.currentSession().merge(dia);
		
		return false;
	}

}
